#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_nonuniform_qualifier : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require


#include "../../../../core/shader_binding_ID.h"
#include "../../../../core/shader_std.h"
#include "../../../../core/shader_built_in_functions.h"


layout(points) in;
layout(line_strip, max_vertices=2) out;

layout(location = 0) in vec3 inEyeDir[];
layout(location = 1) in vec3 inNormal[];
layout(location = 2) in vec4 inVert[];
layout(location = 3) in float inUV[];
layout(location = 4) in uint inMaterialID[];
layout(location = 5) in uint inOffset_Face[];
layout(location = 6) in mat4 inProj[];

//in gl_PerVertex {
//	vec4 gl_Position;
//}gl_in[];



layout(location = 0) out vec3 outEyeDir;
layout(location = 1) out vec3 outNormal;
layout(location = 2) out vec4 outVert;
layout(location = 7) out flat uint outMaterialID;
layout(location = 8) out float outElementID;
layout(location = 9) out float outUV;

out gl_PerVertex {
	vec4 gl_Position;
};


layout(std430, set = 1, scalar, column_major, binding = DEF_BINDING_MeshFaceID) readonly buffer Buf0 {
	S_FaceElement m_Face[];
};



void main(void){

	//vec3 normal = normalize(f_surface_FaceNormal(gl_in[0].gl_Position.xyz, gl_in[1].gl_Position.xyz, gl_in[2].gl_Position.xyz));
	//vec3 normal = normalize(f_surface_FaceNormal(inNormal[0], inNormal[1], inNormal[2]));
	//vec3 normal = normalize(gl_in[0].gl_Position.xyz + gl_in[1].gl_Position.xyz + gl_in[2].gl_Position.xyz);
	
	//S_FaceElement face = m_Face[ inOffset_Face[0] + gl_PrimitiveIDIn];
	
	outEyeDir = inEyeDir[0];
	outNormal = vec3(0);
	outVert = inVert[0];
	outMaterialID = inMaterialID[0];
	gl_Position = inProj[0] * inVert[0];
	//gl_Position = inProj[0] * vec4(3,0,5,1);
	EmitVertex();

	outEyeDir = inEyeDir[0];
	outNormal = vec3(0);
	outVert = inVert[0];
	outMaterialID = inMaterialID[0];
	gl_Position = inProj[0] * vec4(inVert[0].xyz + inNormal[0], 1);
	//gl_Position = inProj[0] * vec4(2,0,5,1);
	EmitVertex();

	EndPrimitive();

	//for(uint i=0; i<2; ++i){
	//	outEyeDir = inEyeDir[i];
	//	outNormal = vec3(0);
	//	outVert = inVert[i];
	//	outMaterialID = inMaterialID[i];
	//	outElementID = face.FacesMooth;
	//	outUV = inUV[i];
	//	
	//	gl_Position = inProj * inVert[i];
	//	//gl_Position = gl_in[i].gl_Position;
	//	EmitVertex();
	//}
	//
	//EndPrimitive();
}



